/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.SQLException;
import pojo.*;

/**
 *
 * @author Thanh Minh drp trai
 */
public class ThuocDAO {
     public static int themLoaiThuoc(Thuoc T){     
        int n=-1;
        try{
        MysqldataAccesshelper helper = new MysqldataAccesshelper();
        helper.open();
         String sql=String.format("INSERT INTO thuoc (MaThuoc,TenThuoc,DonViTinh,GiaBan,MaCDung,TinhTrangSD) VALUES (%d,'%s','%s',%d,%d,%d)",T.getMaThuoc(),T.getTenThuoc(),T.getDonViTinh(),T.getGiaBan(),T.getMaCDung(),T.getTinhTrangSD());
         n = helper.executeUpdate(sql);        
        helper.close();
        }
        catch(SQLException ex){
            System.out.println("Them that bai"+ ex.getMessage());
        }  
         return n;
    }
    public static int chinhSuaLoaiThuoc(int mathuoc , String tenthuoc, String DVT , int giaban,int macdung,int tinntrangSD){     
        int n=-1;
        try{
        MysqldataAccesshelper helper = new MysqldataAccesshelper();
        helper.open();
         String sql=String.format("Update  thuoc set TenThuoc = '%s',DonViTinh = '%s',GiaBan= %d ,MaCDung=%d  ,TinhTrangSD =%d where MaThuoc = %d ",tenthuoc,DVT,giaban,macdung,tinntrangSD,mathuoc );
         n = helper.executeUpdate(sql);        
        helper.close();
        }
        catch(SQLException ex){
            System.out.println("Cap nhat that bai"+ ex.getMessage());
        }  
         return n;
    }
    public static int xoaBenhNhan(int mathuoc){
     int n=-1;
     try{
          MysqldataAccesshelper helper = new MysqldataAccesshelper();
          helper.open();
         String sql=String.format(" DELETE FROM thuoc WHERE MaThuoc = %d",mathuoc);
         n = helper.executeUpdate(sql);        
        helper.close();
     }
     catch(SQLException e )
     {
         System.out.println("khong xoa duoc "+e.getMessage());
     }
     return n;
 }
}
